/**
* @author AlbertDarren
* @contact 2563491540@qq.com
*/
#include <cstdio>

using namespace std;
struct Person
{
    char name[6];
    int yyyy,mm,dd;
} temp_person,oldest,youngest,left,right;
void init()
{
    left.yyyy=youngest.yyyy=1814;
    right.yyyy=oldest.yyyy=2014;
    left.mm=right.mm=oldest.mm=youngest.mm=9;
    left.dd=right.dd=oldest.dd=youngest.dd=6;
}
bool lessEqu(Person a,Person b)
{
    if (a.yyyy!=b.yyyy)
    {
        return a.yyyy<b.yyyy;
    }
    else if (a.mm!=b.mm)
    {
        return a.mm<b.mm;
    }
    else
    {
        return a.dd<=b.dd;
    }
}
int main_1028()
{
    init();
    int N,num=0;
    scanf("%d",&N);
    for (int i=0;i<N ;++i )
    {
        scanf("%s %d/%d/%d",temp_person.name,&temp_person.yyyy,&temp_person.mm,&temp_person.dd);
        if (lessEqu(temp_person,right)&&lessEqu(left,temp_person))
        {
            ++num;
            if (lessEqu(youngest,temp_person))
            {
                youngest=temp_person;
            }
            if (lessEqu(temp_person,oldest))
            {
                oldest=temp_person;
            }
        }
    }
    if (0==num)
    {
        printf("%d\n",num);
    }
    else
    {
        printf("%d %s %s\n",num,oldest.name,youngest.name);
    }
	return 0;
}
